package com.health.fragment.tijian;

import java.util.ArrayList;
import java.util.List;

import com.health.NovaApplication;
import com.health.PersonalFileActivity.onFragmentSave;
import com.health.R;
import com.health.db.FDbManager;
import com.health.fragment.NovaFragment;
import com.health.tablebean.ARCHIVE_MEDI_PHYS_DIST;
import com.health.tablebean.ARCHIVE_VISCERAFUNCTION;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.OLD_MEDICINE_RESULT;
import com.health.activity.tijian.TiJianActivity;
import com.health.activity.tijian.ZYTZ_WenJuanActivity;
import com.health.tools.GlobalConts;
import com.health.view.spinner.NiceSpinner;

import android.content.Intent;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
/**
 * 健康体检-中医体质
 * @author 田相伟
 *
 */
import android.widget.RadioGroup;

/**
 * 中医体质
 * 
 * @author 田相伟
 *
 */
public class HealthTiJian_ZytzFragment extends NovaFragment implements onFragmentSave {
	private static final String TAG = "HealthTiJian_ZytzFragment";
	private Button wenJuanButton;// 体质辨识问卷
	private Button resetButton;// 重置
	private NiceSpinner koucunSpinner;// 口唇下拉
	private NiceSpinner yanbuSpinner;// 咽部下拉
	String IDCARD;// 身份证号
	// RadioGroup
	RadioGroup pinghe;
	RadioGroup qixu;
	RadioGroup yangxu;
	RadioGroup yinxu;
	RadioGroup tanshi;
	RadioGroup shire;
	RadioGroup xueyu;
	RadioGroup qiyu;
	RadioGroup tebing;

	// result radioButton;
	RadioButton result_qixuzhi_1;
	RadioButton result_qixuzhi_2;
	RadioButton result_yangxuzhi_1;
	RadioButton result_yangxuzhi_2;
	RadioButton result_yinxuzhi_1;
	RadioButton result_yinxuzhi_2;
	RadioButton result_tanshizhi_1;
	RadioButton result_tanshizhi_2;
	RadioButton result_shirezhi_1;
	RadioButton result_shirezhi_2;
	RadioButton result_xueyuzhi_1;
	RadioButton result_xueyuzhi_2;
	RadioButton result_qiyuzhi_1;
	RadioButton result_qiyuzhi_2;
	RadioButton result_tebingzhi_1;
	RadioButton result_tebingzhi_2;
	RadioButton result_pinghezhi_1;
	RadioButton result_pinghezhi_2;
	// 数据库
	OLD_MEDICINE_RESULT old_MEDICINE_RESULT;// 中医体质辨识问卷结果表
	ARCHIVE_VISCERAFUNCTION archive_VISCERAFUNCTION;// 健康体检——脏器功能
	ARCHIVE_MEDI_PHYS_DIST archive_MEDI_PHYS_DIST;// 健康体检--中医体质辨识
	FDbManager fdDbManager;
	/***
	 * 脏器功能
	 */
	EditText left_eye;// 左眼视力
	EditText right_eye;// 右眼视力
	EditText left_eye_jiaozheng;// 左眼视力矫正
	EditText right_eye_jiaozheng;// 右眼视力矫正
	RadioGroup sportGroup;
	RadioGroup eyeGroup;
	RadioButton sportOK;
	RadioButton sportNO;
	RadioButton eyeOK;
	RadioButton eyeON;
	View view;

	private CheckBox check_normal;
	private CheckBox check_quechi;
	private CheckBox check_quchi;
	private CheckBox check_yichi;

	private LinearLayout linear_quechi;
	private LinearLayout linear_quchi;
	private LinearLayout linear_yichi;

	private EditText ed_quechi_zs;
	private EditText ed_quechi_zx;
	private EditText ed_quechi_ys;
	private EditText ed_quechi_yx;

	private EditText ed_quchi_zs;
	private EditText ed_quchi_zx;
	private EditText ed_quchi_ys;
	private EditText ed_quchi_yx;

	private EditText ed_yichi_zs;
	private EditText ed_yichi_zx;
	private EditText ed_yichi_ys;
	private EditText ed_yichi_yx;

	private List<BD_DD_INFO> kouchunList = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> yanbuList = new ArrayList<BD_DD_INFO>();

	private String tooth_Id = "";

	private int from_MEDI = -1;
	private int from_VISCERAFUNCTION = -1;

	@Override
	public View findViews(LayoutInflater inflater) {
		view = inflater.inflate(R.layout.healthtijian_zytz_fragment, null);
		fdDbManager = FDbManager.getInstance(getActivity());
		IDCARD = NovaApplication.getUserInfo().getIDCARD();
		initViews(view);
		GlobalConts.setMaxLength(6, left_eye, // 左眼视力
				right_eye, // 右眼视力
				left_eye_jiaozheng, // 左眼视力矫正
				right_eye_jiaozheng// 右眼视力矫正
		);
		GlobalConts.setMaxLength(4, ed_quechi_zs, ed_quechi_zx, ed_quechi_ys, ed_quechi_yx, ed_quchi_zs, ed_quchi_zx,
				ed_quchi_ys, ed_quchi_yx, ed_yichi_zs, ed_yichi_zx, ed_yichi_ys, ed_yichi_yx);
		return view;
	}

	@Override
	public void setupView(View view) {
		// TODO Auto-generated method stub

	}

	@Override
	public void addListener() {
		wenJuanButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(getActivity(), ZYTZ_WenJuanActivity.class);
				startActivity(intent);
			}
		});
		resetButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				pinghe.clearCheck();
				qixu.clearCheck();
				yangxu.clearCheck();
				yinxu.clearCheck();
				tanshi.clearCheck();
				shire.clearCheck();
				xueyu.clearCheck();
				qiyu.clearCheck();
				tebing.clearCheck();
			}
		});

		check_normal.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

				if (isChecked) {
					tooth_Id = "DM100-11_1";
					check_quchi.setChecked(false);
					check_quechi.setChecked(false);
					check_yichi.setChecked(false);

					linear_quechi.setVisibility(View.GONE);
					linear_quchi.setVisibility(View.GONE);
					linear_yichi.setVisibility(View.GONE);

				} else {
					tooth_Id = "";
				}

			}
		});

		check_quechi.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if ("DM100-11_1".equals(tooth_Id)) {
					check_quechi.setChecked(false);
				} else {

					if (isChecked) {
						linear_quechi.setVisibility(View.VISIBLE);
					} else {
						linear_quechi.setVisibility(View.GONE);
						ed_quechi_zs.setText("");
						ed_quechi_zx.setText("");
						ed_quechi_ys.setText("");
						ed_quechi_yx.setText("");
					}
				}

			}
		});
		check_quchi.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if ("DM100-11_1".equals(tooth_Id)) {
					check_quchi.setChecked(false);
				} else {
					if (isChecked) {
						linear_quchi.setVisibility(View.VISIBLE);
					} else {
						linear_quchi.setVisibility(View.GONE);
						ed_quchi_zs.setText("");
						ed_quchi_zx.setText("");
						ed_quchi_ys.setText("");
						ed_quchi_yx.setText("");
					}
				}

			}
		});
		check_yichi.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				try {
					if ("DM100-11_1".equals(tooth_Id)) {
						check_yichi.setChecked(false);
					} else {
						if (isChecked) {
							linear_yichi.setVisibility(View.VISIBLE);
						} else {
							linear_yichi.setVisibility(View.GONE);
							ed_yichi_zs.setText("");
							ed_yichi_zx.setText("");
							ed_yichi_ys.setText("");
							ed_yichi_yx.setText("");
						}
					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
	}

	@Override
	public void setData() {
		archive_MEDI_PHYS_DIST = new ARCHIVE_MEDI_PHYS_DIST();
		archive_VISCERAFUNCTION = new ARCHIVE_VISCERAFUNCTION();
		archive_MEDI_PHYS_DIST.setIDCARD(IDCARD);
		archive_VISCERAFUNCTION.setIDCARD(IDCARD);
		bindSpinner("口唇", "PARENTID = 'DM100-10'");
		bindSpinner("咽部", "PARENTID = 'DM100-12'");

		setData_zytz();
	}
	
	@Override
	public void onResume() {
		super.onResume();
//		setData();
	}

	@Override
	public void save() {
		saveData();

	}

	/**
	 * 设置下拉
	 * 
	 * @param flagName
	 * @param strSql
	 * @author 王婷婷
	 * @date 2015年12月24日 上午9:19:28
	 */

	private void bindSpinner(String flagName, String strSql) {
		List<BD_DD_INFO> sList = new ArrayList<BD_DD_INFO>();
		// BD_DD_INFO bd = new BD_DD_INFO();
		// bd.setDATAINFO("请选择");
		// bd.setID("");
		// sList.add(bd);
		List<BD_DD_INFO> sList1 = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class,
				strSql);
		sList.addAll(sList1);
		if (flagName.equals("口唇")) {
			// nice_adapter_pf = new NiceSpinnerAdapter<>(getActivity(), sList);
			// nice_spinner_pf.setAdapter(nice_adapter_pf);
			kouchunList = sList;
			koucunSpinner.attachDataSource(kouchunList);

		} else if (flagName.equals("咽部")) {
			yanbuList = sList;
			// nice_adapter_gm = new NiceSpinnerAdapter<>(getActivity(), sList);
			yanbuSpinner.attachDataSource(yanbuList);
		}

	}

	/**
	 * 中医体质获取数据
	 * 
	 * @author 王婷婷
	 * @date 2016年1月11日 上午10:28:48
	 */
	private void setData_zytz() {
		try {
			List<ARCHIVE_MEDI_PHYS_DIST> archive_MEDI_PHYS_DISTs = fdDbManager
					.findAllByWhere(ARCHIVE_MEDI_PHYS_DIST.class, "IDCARD='" + IDCARD + "'");
			List<ARCHIVE_VISCERAFUNCTION> archive_VISCERAFUNCTIONs = fdDbManager
					.findAllByWhere(ARCHIVE_VISCERAFUNCTION.class, "IDCARD='" + IDCARD + "'");
			System.out.println(archive_MEDI_PHYS_DISTs.size() + ":" + archive_VISCERAFUNCTIONs.size());
			if (archive_MEDI_PHYS_DISTs.size() > 0) {
				from_MEDI = 1;
				ARCHIVE_MEDI_PHYS_DIST archive_MEDI_PHYS_DIST1 = archive_MEDI_PHYS_DISTs.get(0);
				System.out.println("平和" + archive_MEDI_PHYS_DIST1.getMILD());
				if ("DM100-24_1".equals(archive_MEDI_PHYS_DIST1.getMILD())) {
					result_pinghezhi_1.setChecked(true);
				} else if ("DM100-24_2".equals(archive_MEDI_PHYS_DIST1.getMILD())) {
					result_pinghezhi_2.setChecked(true);
				} else {
					result_pinghezhi_1.setChecked(false);
					result_pinghezhi_2.setChecked(false);
				}
				System.out.println("气虚" + archive_MEDI_PHYS_DIST1.getFAINT());
				if ("DM100-24_1".equals(archive_MEDI_PHYS_DIST1.getFAINT())) {
					result_qixuzhi_1.setChecked(true);
				} else if ("DM100-24_2".equals(archive_MEDI_PHYS_DIST1.getFAINT())) {
					result_qixuzhi_2.setChecked(true);
				} else {
					result_qixuzhi_1.setChecked(false);
					result_qixuzhi_2.setChecked(false);
				}
				System.out.println("阳虚" + archive_MEDI_PHYS_DIST1.getYANG());
				if ("DM100-24_1".equals(archive_MEDI_PHYS_DIST1.getYANG())) {
					result_yangxuzhi_1.setChecked(true);
				} else if ("DM100-24_2".equals(archive_MEDI_PHYS_DIST1.getYANG())) {
					result_yangxuzhi_2.setChecked(true);
				} else {
					result_yangxuzhi_1.setChecked(false);
					result_yangxuzhi_2.setChecked(false);
				}
				System.out.println("阴虚" + archive_MEDI_PHYS_DIST1.getYIN());
				if ("DM100-24_1".equals(archive_MEDI_PHYS_DIST1.getYIN())) {
					result_yinxuzhi_1.setChecked(true);
				} else if ("DM100-24_2".equals(archive_MEDI_PHYS_DIST1.getYIN())) {
					result_yinxuzhi_2.setChecked(true);
				} else {
					result_yinxuzhi_1.setChecked(false);
					result_yinxuzhi_2.setChecked(false);
				}
				System.out.println("痰湿" + archive_MEDI_PHYS_DIST1.getPHLEGMDAMP());
				if ("DM100-24_1".equals(archive_MEDI_PHYS_DIST1.getPHLEGMDAMP())) {
					result_tanshizhi_1.setChecked(true);
				} else if ("DM100-24_2".equals(archive_MEDI_PHYS_DIST1.getPHLEGMDAMP())) {
					result_tanshizhi_2.setChecked(true);
				} else {
					result_tanshizhi_1.setChecked(false);
					result_tanshizhi_2.setChecked(false);
				}
				System.out.println("湿热" + archive_MEDI_PHYS_DIST1.getMUGGY());
				if ("DM100-24_1".equals(archive_MEDI_PHYS_DIST1.getMUGGY())) {
					result_shirezhi_1.setChecked(true);
				} else if ("DM100-24_2".equals(archive_MEDI_PHYS_DIST1.getMUGGY())) {
					result_shirezhi_2.setChecked(true);
				} else {
					result_shirezhi_1.setChecked(false);
					result_shirezhi_2.setChecked(false);
				}
				System.out.println("血郁" + archive_MEDI_PHYS_DIST1.getBLOODSTASIS());
				if ("DM100-24_1".equals(archive_MEDI_PHYS_DIST1.getBLOODSTASIS())) {
					result_xueyuzhi_1.setChecked(true);
				} else if ("DM100-24_2".equals(archive_MEDI_PHYS_DIST1.getBLOODSTASIS())) {
					result_xueyuzhi_2.setChecked(true);
				} else {
					result_xueyuzhi_1.setChecked(false);
					result_xueyuzhi_2.setChecked(false);
				}
				System.out.println("气郁" + archive_MEDI_PHYS_DIST1.getQICONSTRAINT());
				if ("DM100-24_1".equals(archive_MEDI_PHYS_DIST1.getQICONSTRAINT())) {
					result_qiyuzhi_1.setChecked(true);
				} else if ("DM100-24_2".equals(archive_MEDI_PHYS_DIST1.getQICONSTRAINT())) {
					result_qiyuzhi_2.setChecked(true);
				} else {
					result_qiyuzhi_1.setChecked(false);
					result_qiyuzhi_2.setChecked(false);
				}
				System.out.println("特秉" + archive_MEDI_PHYS_DIST1.getCHARACTERISTIC());
				if ("DM100-24_1".equals(archive_MEDI_PHYS_DIST1.getCHARACTERISTIC())) {
					result_tebingzhi_1.setChecked(true);
				} else if ("DM100-24_2".equals(archive_MEDI_PHYS_DIST1.getCHARACTERISTIC())) {
					result_tebingzhi_2.setChecked(true);
				} else {
					result_tebingzhi_1.setChecked(false);
					result_tebingzhi_2.setChecked(false);
				}
			} else {
				from_MEDI = 0;
			}
			if (archive_VISCERAFUNCTIONs.size() > 0) {
				from_VISCERAFUNCTION = 1;
				ARCHIVE_VISCERAFUNCTION ques = archive_VISCERAFUNCTIONs.get(0);

				koucunSpinner.setSelectedIndex(getListIndex(ques.getLIPS(), kouchunList));
				yanbuSpinner.setSelectedIndex(getListIndex(ques.getPHARYNGEAL(), yanbuList));

				Log.w(TAG, ques.getLEFTVIEW());
				// if (ques.getLEFTVIEW() != -1.00) {
				left_eye.setText(ques.getLEFTVIEW());
				// } else {
				// left_eye.setText("");
				// }
				// if (ques.getRIGHTVIEW() != -1.00) {
				right_eye.setText(ques.getRIGHTVIEW());
				// } else {
				// right_eye.setText("");
				// }
				// if (ques.getLEFTEYECORRECT() != -1.00) {
				left_eye_jiaozheng.setText(ques.getLEFTEYECORRECT());
				// } else {
				// left_eye_jiaozheng.setText("");
				// }
				// if (ques.getRIGHTEYECORRECT() != -1.00) {
				right_eye_jiaozheng.setText(ques.getRIGHTEYECORRECT());
				// } else {
				// right_eye_jiaozheng.setText("");
				// }
				if ("DM100-13_1".equals(ques.getLISTEN())) {
					eyeOK.setChecked(true);
				} else if ("DM100-13_2".equals(ques.getLISTEN())) {
					eyeON.setChecked(true);
				}
				if ("DM100-14_1".equals(ques.getSPORTFUNCTION())) {
					sportOK.setChecked(true);
				} else if ("DM100-14_2".equals(ques.getSPORTFUNCTION())) {
					sportNO.setChecked(true);
				}

				tooth_Id = ques.getTOOTHRESIDES();
				if (!TextUtils.isEmpty(tooth_Id)) {
					if (tooth_Id.equals("DM100-11_1")) {
						check_normal.setChecked(true);
					} else {
						if (tooth_Id.contains("DM100-11_2")) {
							ed_quechi_zs.setText(ques.getQUECHILEFTUP());
							ed_quechi_zx.setText(ques.getQUECHILEFTDOWN());
							ed_quechi_ys.setText(ques.getQUECHIRIGHTUP());
							ed_quechi_yx.setText(ques.getQUECHIRIGHTDOWN());
							check_quechi.setChecked(true);
						}
						if (tooth_Id.contains("DM100-11_3")) {
							ed_quchi_zs.setText(ques.getQUCHILEFTUP());
							ed_quchi_zx.setText(ques.getQUCHILEFTDOWN());
							ed_quchi_ys.setText(ques.getQUCHIRIGHTUP());
							ed_quchi_yx.setText(ques.getQUCHIRIGHTDOWN());
							check_quchi.setChecked(true);
						}
						if (tooth_Id.contains("DM100-11_4")) {
							ed_yichi_zs.setText(ques.getYICHILEFTUP());
							ed_yichi_zx.setText(ques.getYICHILEFTDOWN());
							ed_yichi_ys.setText(ques.getYICHIRIGHTUP());
							ed_yichi_yx.setText(ques.getYICHIRIGHTDOWN());
							check_yichi.setChecked(true);
						}
					}

				}

			} else {
				from_VISCERAFUNCTION = 0;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/**
	 * 初始化界面布局
	 * 
	 * @param view
	 * @author 王婷婷
	 * @date 2016年1月9日 上午10:44:44
	 */
	private void initViews(View view) {
		koucunSpinner = (NiceSpinner) view.findViewById(R.id.koucun_spinner);
		yanbuSpinner = (NiceSpinner) view.findViewById(R.id.yanbu_spinner);
		wenJuanButton = (Button) view.findViewById(R.id.wenjuan);
		resetButton = (Button) view.findViewById(R.id.reset);
		// RadioGroup
		pinghe = (RadioGroup) view.findViewById(R.id.pinghezhi_radiogroup);
		qixu = (RadioGroup) view.findViewById(R.id.qixuzhi_radiogroup);
		yangxu = (RadioGroup) view.findViewById(R.id.yangxuzhi_radiogroup);
		yinxu = (RadioGroup) view.findViewById(R.id.yinxuzhi_radiogroup);
		tanshi = (RadioGroup) view.findViewById(R.id.tanshizhi_radiogroup);
		shire = (RadioGroup) view.findViewById(R.id.shirezhi_radiogroup);
		xueyu = (RadioGroup) view.findViewById(R.id.xueyuzhi_radiogroup);
		qiyu = (RadioGroup) view.findViewById(R.id.qiyuzhi_radiogroup);
		tebing = (RadioGroup) view.findViewById(R.id.tebingzhi_radiogroup);
		// result RadioButton
		result_qixuzhi_1 = (RadioButton) view.findViewById(R.id.qixuzhi_1);
		result_qixuzhi_2 = (RadioButton) view.findViewById(R.id.qixuzhi_2);
		result_yangxuzhi_1 = (RadioButton) view.findViewById(R.id.yangxuzhi_1);
		result_yangxuzhi_2 = (RadioButton) view.findViewById(R.id.yangxuzhi_2);
		result_yinxuzhi_1 = (RadioButton) view.findViewById(R.id.yinxuzhi_1);
		result_yinxuzhi_2 = (RadioButton) view.findViewById(R.id.yinxuzhi_2);
		result_tanshizhi_1 = (RadioButton) view.findViewById(R.id.tanshizhi_1);
		result_tanshizhi_2 = (RadioButton) view.findViewById(R.id.tanshizhi_2);
		result_shirezhi_1 = (RadioButton) view.findViewById(R.id.shirezhi_1);
		result_shirezhi_2 = (RadioButton) view.findViewById(R.id.shirezhi_2);
		result_xueyuzhi_1 = (RadioButton) view.findViewById(R.id.xueyuzhi_1);
		result_xueyuzhi_2 = (RadioButton) view.findViewById(R.id.xueyuzhi_2);
		result_qiyuzhi_1 = (RadioButton) view.findViewById(R.id.qiyuzhi_1);
		result_qiyuzhi_2 = (RadioButton) view.findViewById(R.id.qiyuzhi_2);
		result_tebingzhi_1 = (RadioButton) view.findViewById(R.id.tebingzhi_1);
		result_tebingzhi_2 = (RadioButton) view.findViewById(R.id.tebingzhi_2);
		result_pinghezhi_1 = (RadioButton) view.findViewById(R.id.pinghezhi_1);
		result_pinghezhi_2 = (RadioButton) view.findViewById(R.id.pinghezhi_2);
		// 脏器功能
		left_eye = (EditText) view.findViewById(R.id.zuoyan_edit);
		right_eye = (EditText) view.findViewById(R.id.youyan_edit);
		left_eye_jiaozheng = (EditText) view.findViewById(R.id.jiaozheng_zuoyan_edit);
		right_eye_jiaozheng = (EditText) view.findViewById(R.id.jiaozheng_youyan_edit);
		sportGroup = (RadioGroup) view.findViewById(R.id.sport_radiogroup);
		eyeGroup = (RadioGroup) view.findViewById(R.id.tingli_radiogroup);
		eyeOK = (RadioButton) view.findViewById(R.id.eye_ok);
		eyeON = (RadioButton) view.findViewById(R.id.eye_no);
		sportOK = (RadioButton) view.findViewById(R.id.sport_ok);
		sportNO = (RadioButton) view.findViewById(R.id.sport_no);

		check_normal = (CheckBox) view.findViewById(R.id.normal);
		check_quechi = (CheckBox) view.findViewById(R.id.quechi);
		check_quchi = (CheckBox) view.findViewById(R.id.quchi);
		check_yichi = (CheckBox) view.findViewById(R.id.yichi);

		linear_quechi = (LinearLayout) view.findViewById(R.id.linear_quechi);
		linear_quchi = (LinearLayout) view.findViewById(R.id.linear_quchi);
		linear_yichi = (LinearLayout) view.findViewById(R.id.linear_yichi);

		ed_quechi_zs = (EditText) view.findViewById(R.id.ed_quechi_zs);
		ed_quechi_zx = (EditText) view.findViewById(R.id.ed_quechi_zx);
		ed_quechi_ys = (EditText) view.findViewById(R.id.ed_quechi_ys);
		ed_quechi_yx = (EditText) view.findViewById(R.id.ed_quechi_yx);

		ed_quchi_zs = (EditText) view.findViewById(R.id.ed_quchi_zs);
		ed_quchi_zx = (EditText) view.findViewById(R.id.ed_quchi_zx);
		ed_quchi_ys = (EditText) view.findViewById(R.id.ed_quchi_ys);
		ed_quchi_yx = (EditText) view.findViewById(R.id.ed_quchi_yx);

		ed_yichi_zs = (EditText) view.findViewById(R.id.ed_yichi_zs);
		ed_yichi_zx = (EditText) view.findViewById(R.id.ed_yichi_zx);
		ed_yichi_ys = (EditText) view.findViewById(R.id.ed_yichi_ys);
		ed_yichi_yx = (EditText) view.findViewById(R.id.ed_yichi_yx);

	}

	@Override
	public void onStart() {
		super.onStart();
		setData_zytz();
	}

	public void saveData() {
		String str_lefteye = left_eye.getText().toString();
		if (TextUtils.isEmpty(str_lefteye)) {
			left_eye.setBackgroundColor(Color.YELLOW);
			((TiJianActivity) getActivity()).showTextDialog("请填写左眼视力");
			return;
		} else {
			left_eye.setBackgroundColor(Color.WHITE);
		}

		String str_righteye = right_eye.getText().toString();
		if (TextUtils.isEmpty(str_righteye)) {
			right_eye.setBackgroundColor(Color.YELLOW);
			((TiJianActivity) getActivity()).showTextDialog("请填写右眼视力");
			return;
		} else {
			right_eye.setBackgroundColor(Color.WHITE);
		}

//		if (!check_normal.isChecked() && !check_quechi.isChecked() &&! check_quchi.isChecked()
//				&& !check_yichi.isChecked()) {
//			((TiJianActivity) getActivity()).showTextDialog("请填写齿列");
//			return;
//		}
//		
//		if (!sportOK.isChecked()&&!sportNO.isChecked()) {
//			((TiJianActivity) getActivity()).showTextDialog("请填写运动功能");
//			return;
//		}
//		
//		if (!eyeOK.isChecked()&&!eyeOK.isChecked()) {
//			((TiJianActivity) getActivity()).showTextDialog("请填写听力");
//			return;
//		}

		saveZangqi();
		if (from_VISCERAFUNCTION == 1) {
			fdDbManager.updata(archive_VISCERAFUNCTION, "IDCARD='" + IDCARD + "'");
			System.out.println("修改123");
		} else {
			fdDbManager.save(archive_VISCERAFUNCTION);
			System.out.println("新建123");
			from_VISCERAFUNCTION = 1;
		}
		zhongyitz();
		if (from_MEDI == 1) {
			fdDbManager.updata(archive_MEDI_PHYS_DIST, "IDCARD='" + IDCARD + "'");
			System.out.println("修改");
		} else {
			fdDbManager.save(archive_MEDI_PHYS_DIST);
			System.out.println("新建");
			from_MEDI = 1;
		}
		((TiJianActivity) getActivity()).showTextDialog("保存成功");
	}

	public void saveZangqi() {
		tooth_Id = "";
		System.out.println("口唇" + kouchunList.get(koucunSpinner.getSelectedIndex()).getID());
		archive_VISCERAFUNCTION.setLIPS(kouchunList.get(koucunSpinner.getSelectedIndex()).getID());

		archive_VISCERAFUNCTION.setPHARYNGEAL(yanbuList.get(yanbuSpinner.getSelectedIndex()).getID());
		// TODO
		// archive_VISCERAFUNCTION.setTOOTHRESIDES(chilieSpinner.getSelectedIndex()
		// + "");
		// 正常DM100-11_1 、 缺齿DM100-11_2、龋齿 DM100-11_3、义齿 DM100-11_4
		if (check_normal.isChecked()) {
			tooth_Id = "DM100-11_1";
		} else if (check_quechi.isChecked() || check_quchi.isChecked() || check_yichi.isChecked()) {

			if (check_quechi.isChecked()) {
				if (!TextUtils.isEmpty(tooth_Id)) {
					tooth_Id = tooth_Id + "," + "DM100-11_2";
				} else {
					tooth_Id = "DM100-11_2";
				}

			}
			if (check_quchi.isChecked()) {
				if (!TextUtils.isEmpty(tooth_Id)) {
					tooth_Id = tooth_Id + "," + "DM100-11_3";
				} else {
					tooth_Id = "DM100-11_3";
				}
			}
			if (check_yichi.isChecked()) {
				if (!TextUtils.isEmpty(tooth_Id)) {
					tooth_Id = tooth_Id + "," + "DM100-11_4";
				} else {
					tooth_Id = "DM100-11_4";
				}
			}
		}
		System.out.println("齿列1" + tooth_Id);
		if (tooth_Id != null) {
			if (!tooth_Id.equals("") || tooth_Id.contains(",")) {
				System.out.println("齿列" + tooth_Id);
				if (!tooth_Id.equals("")) {
					archive_VISCERAFUNCTION.setTOOTHRESIDES(tooth_Id);
					if (tooth_Id.contains("DM100-11_1")) {
					} else {
						if (tooth_Id.contains("DM100-11_2")) {
							archive_VISCERAFUNCTION.setQUECHILEFTUP(ed_quechi_zs.getText().toString());
							archive_VISCERAFUNCTION.setQUECHILEFTDOWN(ed_quechi_zx.getText().toString());
							archive_VISCERAFUNCTION.setQUECHIRIGHTUP(ed_quechi_ys.getText().toString());
							archive_VISCERAFUNCTION.setQUECHIRIGHTDOWN(ed_quechi_yx.getText().toString());
						}
						if (tooth_Id.contains("DM100-11_3")) {
							archive_VISCERAFUNCTION.setQUCHILEFTUP(ed_quchi_zs.getText().toString());
							archive_VISCERAFUNCTION.setQUCHILEFTDOWN(ed_quchi_zx.getText().toString());
							archive_VISCERAFUNCTION.setQUCHIRIGHTUP(ed_quchi_ys.getText().toString());
							archive_VISCERAFUNCTION.setQUCHIRIGHTDOWN(ed_quchi_yx.getText().toString());
						}
						if (tooth_Id.contains("DM100-11_4")) {
							archive_VISCERAFUNCTION.setYICHILEFTUP(ed_yichi_zs.getText().toString());
							archive_VISCERAFUNCTION.setYICHILEFTDOWN(ed_yichi_zx.getText().toString());
							archive_VISCERAFUNCTION.setYICHIRIGHTUP(ed_yichi_ys.getText().toString());
							archive_VISCERAFUNCTION.setYICHIRIGHTDOWN(ed_yichi_yx.getText().toString());
						}
					}
				}
			}

		}

		Log.w(TAG, left_eye.getText().toString());
		// if (!TextUtils.isEmpty(left_eye.getText().toString())) {
		archive_VISCERAFUNCTION.setLEFTVIEW(left_eye.getText().toString());
		// } else {
		// archive_VISCERAFUNCTION.setLEFTVIEW(-1.00);
		// }
		// if (!TextUtils.isEmpty(right_eye.getText().toString())) {
		archive_VISCERAFUNCTION.setRIGHTVIEW(right_eye.getText().toString());
		// } else {
		// archive_VISCERAFUNCTION.setRIGHTVIEW(-1.00);
		// }
		// if (!TextUtils.isEmpty(left_eye_jiaozheng.getText().toString())) {
		archive_VISCERAFUNCTION.setLEFTEYECORRECT(left_eye_jiaozheng.getText().toString());
		// } else {
		// archive_VISCERAFUNCTION.setLEFTEYECORRECT(-1.00);
		// }
		// if (!TextUtils.isEmpty(right_eye_jiaozheng.getText().toString())) {
		archive_VISCERAFUNCTION.setRIGHTEYECORRECT(right_eye_jiaozheng.getText().toString());
		// } else {
		// archive_VISCERAFUNCTION.setRIGHTEYECORRECT(-1.00);
		// }
		if ((RadioButton) view.findViewById(sportGroup.getCheckedRadioButtonId()) != null) {
			String sportChecked = ((RadioButton) view.findViewById(sportGroup.getCheckedRadioButtonId())).getText()
					.toString();
			if ("可以顺利完成".equals(sportChecked)) {
				archive_VISCERAFUNCTION.setSPORTFUNCTION("DM100-14_1");
			} else if ("无法独立完成任何一个动作".equals(sportChecked)) {
				archive_VISCERAFUNCTION.setSPORTFUNCTION("DM100-14_2");
			}
		} else {
			archive_VISCERAFUNCTION.setSPORTFUNCTION("");
		}
		if ((RadioButton) view.findViewById(eyeGroup.getCheckedRadioButtonId()) != null) {
			String eyeChecked = ((RadioButton) view.findViewById(eyeGroup.getCheckedRadioButtonId())).getText()
					.toString();
			if ("听见".equals(eyeChecked)) {
				archive_VISCERAFUNCTION.setLISTEN("DM100-13_1");
			} else if ("听不清或无法听见".equals(eyeChecked)) {
				archive_VISCERAFUNCTION.setLISTEN("DM100-13_2");
			}
		} else {
			archive_VISCERAFUNCTION.setLISTEN("");
		}

	}

	public void zhongyitz() {
		if ((RadioButton) view.findViewById(pinghe.getCheckedRadioButtonId()) != null) {
			String pingheChecked = ((RadioButton) view.findViewById(pinghe.getCheckedRadioButtonId())).getText()
					.toString();
			System.out.println("***********" + pingheChecked);
			if ("是".equals(pingheChecked)) {
				archive_MEDI_PHYS_DIST.setMILD("DM100-24_1");
			} else if ("基本是".equals(pingheChecked)) {
				archive_MEDI_PHYS_DIST.setMILD("DM100-24_2");
			}
		} else {

			archive_MEDI_PHYS_DIST.setMILD("");
		}
		if ((RadioButton) view.findViewById(qixu.getCheckedRadioButtonId()) != null) {
			String qixuChecked = ((RadioButton) view.findViewById(qixu.getCheckedRadioButtonId())).getText().toString();
			if ("是".equals(qixuChecked)) {
				archive_MEDI_PHYS_DIST.setFAINT("DM100-24_1");
			} else if ("基本是".equals(qixuChecked)) {
				archive_MEDI_PHYS_DIST.setFAINT("DM100-24_2");
			}
		} else {
			archive_MEDI_PHYS_DIST.setFAINT("");
		}
		if ((RadioButton) view.findViewById(yangxu.getCheckedRadioButtonId()) != null) {
			String yangxuChecked = ((RadioButton) view.findViewById(yangxu.getCheckedRadioButtonId())).getText()
					.toString();
			if ("是".equals(yangxuChecked)) {
				archive_MEDI_PHYS_DIST.setYANG("DM100-24_1");
			} else if ("基本是".equals(yangxuChecked)) {
				archive_MEDI_PHYS_DIST.setYANG("DM100-24_2");
			}
		} else {
			archive_MEDI_PHYS_DIST.setYANG("");
		}
		if ((RadioButton) view.findViewById(yinxu.getCheckedRadioButtonId()) != null) {
			String yinxuChecked = ((RadioButton) view.findViewById(yinxu.getCheckedRadioButtonId())).getText()
					.toString();

			if ("是".equals(yinxuChecked)) {
				archive_MEDI_PHYS_DIST.setYIN("DM100-24_1");
			} else if ("基本是".equals(yinxuChecked)) {
				archive_MEDI_PHYS_DIST.setYIN("DM100-24_2");
			}
		} else {
			archive_MEDI_PHYS_DIST.setYIN("");
		}
		if ((RadioButton) view.findViewById(tanshi.getCheckedRadioButtonId()) != null) {
			String tanshiChecked = ((RadioButton) view.findViewById(tanshi.getCheckedRadioButtonId())).getText()
					.toString();
			if ("是".equals(tanshiChecked)) {
				archive_MEDI_PHYS_DIST.setPHLEGMDAMP("DM100-24_1");
			} else if ("基本是".equals(tanshiChecked)) {
				archive_MEDI_PHYS_DIST.setPHLEGMDAMP("DM100-24_2");
			}
		} else {
			archive_MEDI_PHYS_DIST.setPHLEGMDAMP("");
		}
		if ((RadioButton) view.findViewById(shire.getCheckedRadioButtonId()) != null) {
			String shireChecked = ((RadioButton) view.findViewById(shire.getCheckedRadioButtonId())).getText()
					.toString();
			if ("是".equals(shireChecked)) {
				archive_MEDI_PHYS_DIST.setMUGGY("DM100-24_1");
			} else if ("基本是".equals(shireChecked)) {
				archive_MEDI_PHYS_DIST.setMUGGY("DM100-24_2");
			}
		} else {
			archive_MEDI_PHYS_DIST.setMUGGY("");
		}
		if ((RadioButton) view.findViewById(xueyu.getCheckedRadioButtonId()) != null) {
			String xueyuChecked = ((RadioButton) view.findViewById(xueyu.getCheckedRadioButtonId())).getText()
					.toString();

			if ("是".equals(xueyuChecked)) {
				archive_MEDI_PHYS_DIST.setBLOODSTASIS("DM100-24_1");
			} else if ("基本是".equals(xueyuChecked)) {
				archive_MEDI_PHYS_DIST.setBLOODSTASIS("DM100-24_2");
			}
		} else {
			archive_MEDI_PHYS_DIST.setBLOODSTASIS("");
		}
		if ((RadioButton) view.findViewById(qiyu.getCheckedRadioButtonId()) != null) {
			String qiyuChecked = ((RadioButton) view.findViewById(qiyu.getCheckedRadioButtonId())).getText().toString();
			if ("是".equals(qiyuChecked)) {
				archive_MEDI_PHYS_DIST.setQICONSTRAINT("DM100-24_1");
			} else if ("基本是".equals(qiyuChecked)) {
				archive_MEDI_PHYS_DIST.setQICONSTRAINT("DM100-24_2");
			}
		} else {
			archive_MEDI_PHYS_DIST.setQICONSTRAINT("");
		}
		if ((RadioButton) view.findViewById(tebing.getCheckedRadioButtonId()) != null) {
			String tebingChecked = ((RadioButton) view.findViewById(tebing.getCheckedRadioButtonId())).getText()
					.toString();

			if ("是".equals(tebingChecked)) {
				archive_MEDI_PHYS_DIST.setCHARACTERISTIC("DM100-24_1");
			} else if ("基本是".equals(tebingChecked)) {
				archive_MEDI_PHYS_DIST.setCHARACTERISTIC("DM100-24_2");
			}
		} else {
			archive_MEDI_PHYS_DIST.setCHARACTERISTIC("");
		}

	}

	private int getListIndex(String str, List<BD_DD_INFO> bds) {
		if (str != null && !str.equals("")) {

			for (int i = 0; i < bds.size(); i++) {
				if (str.equals(bds.get(i).getID())) {
					return i;
				}
			}
		}
		return 0;
	}
}
